package cn.player.media.util;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.widget.PopupWindow;
import android.widget.Toast;

/**
 * 对话框工具类
 *
 * @author silence
 * @version [版本号, 2011-5-27]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class DialogUtil {
    /**
     * DialogUtils实例
     */
    private static DialogUtil mDialogUtils;

    /**
     * Dialog实例
     */
    private Dialog mDialog;

    /**
     * 进度对话框
     */
    private ProgressDialog mProgress;

    /**
     * Toast
     */
    private Toast mToast;


    /**
     * 获取DialogUtils单例
     *
     * @return
     * @see [类、类#方法、类#成员]
     */
    public static DialogUtil getInstance() {
        if (mDialogUtils == null) {
            mDialogUtils = new DialogUtil();
        }
        return mDialogUtils;
    }

    /**
     * 关闭提示对话框
     *
     * @see [类、类#方法、类#成员]
     */
    public void closeDialog() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }

    /**
     * 关闭提示对话框
     *
     * @see [类、类#方法、类#成员]
     */
    public void closeProgressDialog() {
        if (mProgress != null && mProgress.isShowing()) {
            mProgress.dismiss();
        }
    }

    /**
     * 显示Toast信息
     *
     * @see [类、类#方法、类#成员]
     */
    public void showToast(Context context, String message) {
        if (mToast == null) {
            mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
        }
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.setText(message);
        mToast.show();
    }

    /**
     * 关闭Popup窗口
     *
     * @param mPopup PopupWindow
     * @see [类、类#方法、类#成员]
     */
    public void displayPopup(PopupWindow mPopup) {
        if (mPopup != null) {
            if (mPopup.isShowing()) {
                mPopup.dismiss();
            }
        }
    }

    /**
     * 显示Toast信息
     *
     * @see [类、类#方法、类#成员]
     */
    public void showToast(Context context, int msgRes) {
        if (context != null) {

            if (mToast == null) {
                mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
            }
            mToast.setDuration(Toast.LENGTH_SHORT);
            mToast.setText(msgRes);
            mToast.show();
        }
    }

    public ProgressDialog createProgress(Context context, int resId) {
        ProgressDialog dialog = new ProgressDialog(context);
//		dialog.getWindow().setWindowAnimations(R.style.popupAnimationAlpha);
        dialog.setMessage(context.getResources().getString(resId));
        dialog.setIndeterminate(false);
        dialog.setCancelable(true);
        return dialog;
    }
}
